package net.sx.minemodule.mvp.activities;

import android.os.Bundle;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.homegoods.aroutercomment.ARouterPath;
import com.homegoods.aroutercomment.UserService;
import com.homegoods.login.KGetVerHelper;
import com.kedll.library.base.MyBaseFragmentActivity;
import com.kedll.library.mvp.BasePresenter;
import com.kedll.library.mvp.BaseView;

import net.sx.minemodule.R;
import net.sx.minemodule.databinding.MineActivityMineUpdatePayPasswordBinding;
import net.sx.minemodule.mvp.presenters.MineLoginPasswordPresenter;
import net.sx.minemodule.mvp.presenters.MineUpdatePayPasswordPresenter;

/**
 * 修改支付密码
 *
 * @author 11470
 */
@Route(path = ARouterPath.PATH_MINE_UPDATE_PAY_PASSWORD)
public class MineUpdatePayPasswordActivity extends MyBaseFragmentActivity<MineActivityMineUpdatePayPasswordBinding, MineUpdatePayPasswordPresenter> {
    @Autowired(name = ARouterPath.PATH_USER_SERVICE)
    public UserService userService;

    private KGetVerHelper kGetVerHelper;


    @Override
    protected int getLayout() {
        return R.layout.mine_activity_mine_update_pay_password;
    }


    @Override
    protected void initToolBar(Bundle savedInstanceState) {
        super.initToolBar(savedInstanceState);
        setTitle("修改支付密码");
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        ARouter.getInstance().inject(this);
        mBinding.tvOldBindingPhoneUpdatePassword.setText(userService.getMobile());
        mBinding.tvBindingNewPhone.setEnabled(true);
    }

    @Override
    protected MineUpdatePayPasswordPresenter getPresenter() {
        kGetVerHelper = new KGetVerHelper(this, mBinding.getVer);
        return new MineUpdatePayPasswordPresenter(kGetVerHelper);
    }

    @Override
    protected void initEvent() {
        mBinding.setPayPassword(mPresenter);
        // 获取验证码
        mBinding.getVer.setOnClickListener(v -> {
            mPresenter.getVerCode(userService.getMobile());
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (kGetVerHelper != null) {
            kGetVerHelper.restart();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (kGetVerHelper != null) {
            kGetVerHelper.cancel();
            kGetVerHelper = null;
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (kGetVerHelper != null) {
            kGetVerHelper.stop();
        }
    }
}
